package easy;

public class LengthOfLastWord {
    public int lengthOfLastWord0(String s) {
        String []strs = s.split(" ");
        int length = strs.length;
        String str = null;
        if(length!=0){
            str = strs[length-1];
            return str.length();
        }

        return 0;
    }

    public int lengthOfLastWord(String s){
        s = s.trim();
        int lastIndex = s.lastIndexOf(" ");
        return s.length()-lastIndex;
    }
}
